package org.stone.project.common.utils;

import com.alibaba.excel.EasyExcel;
import org.stone.project.common.config.CustomCellWriteHeightConfig;
import org.stone.project.common.config.CustomCellWriteWidthConfig;

import java.io.OutputStream;
import java.util.Collection;

/**
 * excel工具
 */
public class EasyUtil {
    /**
     * 导出数据
     * @param data
     * @param clazz
     * @param out
     * @param <T>
     */
    public static  <T> void exportExcel(Collection<T> data,Class<T> clazz,String sheetName, OutputStream out){
        EasyExcel.write(out, clazz)
                .sheet(sheetName)
                .registerWriteHandler(new CustomCellWriteHeightConfig())
                .registerWriteHandler(new CustomCellWriteWidthConfig())
                .doWrite(data);
    }
}
